package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-26 00:37
 **/
public class LeetCode1078 {

    public String[] findOcurrences(String text, String first, String second) {
        List<String> list = new ArrayList<>();
        String[] strs = text.split(" ");
        int n = strs.length;
        for (int i = 0; i < n - 2; ++i) {
            if (first.equals(strs[i]) && second.equals(strs[i + 1])) {
                list.add(strs[i + 2]);
            }
        }

        return list.toArray(new String[0]);
    }

    public static void main(String[] args) {
        LeetCode1078 code = new LeetCode1078();
        System.out.println(Arrays.toString(code.findOcurrences("alice is a good girl she is a good student", "a", "good")) );
    }

}
